package com.online.player.client.pages;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.media.client.Video;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.online.player.client.IPage;

public class ManageVideoPage implements IPage {

    private Grid form;
    private Video player;

    public ManageVideoPage() {
        RootPanel panel = RootPanel.get("main-content");

        form = new Grid(3, 2);
        final TextBox name = new TextBox();
        TextBox url = new TextBox();
        Button addBtn = new Button("Add");
        addBtn.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                player.addSource(name.getText());
                player.play();
            }
        });
        form.setWidget(0, 0, new Label("Name"));
        form.setWidget(0, 1, name);
        form.setWidget(1, 0, new Label("Video URL"));
        form.setWidget(1, 1, url);
        form.setWidget(2, 0, addBtn);
        form.setVisible(false);
        panel.add(form);

        RootPanel playerPContainer = RootPanel.get("container");
        player = Video.createIfSupported();
        player.setControls(true);
        player.addSource("http://www.w3schools.com/html/mov_bbb.mp4", "video/mp4");
        playerPContainer.add(player);
    }

    public void show() {
        form.setVisible(true);
        // player.play();
        call();
        if (!Video.isSupported())
            Window.alert("Video not supported");
    }

    private native void call()/*-{
                              $wnd.myfunction();
                              }-*/;

    public void hide() {
        form.setVisible(false);
        player.pause();
    }

}
